package com.md.api.controller;

import com.md.api.annotation.NoRepeatSubmit;
import com.md.api.common.utils.StringUtils;
import com.md.api.entity.HttpResult;
import com.md.api.entity.RecycleBin;
import com.md.api.entity.dto.ComposeCommitDto;
import com.md.api.entity.dto.ComposeQueryDto;
import com.md.api.service.RecycleBinSevice;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Slf4j
@RequestMapping("/recycle")
@RestController
public class RecycleBinController {

	@Resource
	RecycleBinSevice recycleBinSevice;


	//回收
	@NoRepeatSubmit
	@RequestMapping("/recovery")
	@ResponseBody
	public HttpResult recovery(HttpServletRequest request, @RequestBody ComposeCommitDto commitDto) {
		if ((null==commitDto.getRecycleType()&& StringUtils.isEmpty(commitDto.getPhotoId()))
				||(null==commitDto.getRecycleType()&& CollectionUtils.isEmpty(commitDto.getPictureIds()))){
			return HttpResult.PARAM_ERROR;
		}
		return recycleBinSevice.recovery(request,commitDto);
	}


	//回收站列表
	@RequestMapping("/recoveryPage")
	@ResponseBody
	public HttpResult recoveryPage(HttpServletRequest request,@RequestBody ComposeQueryDto qto) {
		return recycleBinSevice.recoveryPage(request,qto);
	}

	//恢复
	@NoRepeatSubmit
	@RequestMapping("/restore")
	@ResponseBody
	public HttpResult restore(HttpServletRequest request, @RequestBody RecycleBin recycle) {
		if (null==recycle.getRecycleType()|| StringUtils.isEmpty(recycle.getOnlyId())){
			return HttpResult.PARAM_ERROR;
		}
		return recycleBinSevice.restore(request,recycle);
	}

	//删除
	@NoRepeatSubmit
	@RequestMapping("/remove")
	@ResponseBody
	public HttpResult remove(HttpServletRequest request, @RequestBody ComposeCommitDto dto) {
		if (CollectionUtils.isEmpty(dto.getDeleteIds())){
			return HttpResult.PARAM_ERROR;
		}
		return recycleBinSevice.remove(request,dto);
	}
}
